/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: LogTaskFactory
 * Author:   zhouheng
 * Date:     2018/7/10 22:44
 * Description: 日志操作认为创建工厂
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.core.log.factory;

import com.hengby.hengcrud.core.common.status.LogType;
import com.hengby.hengcrud.core.constants.LogSucceed;
import com.hengby.hengcrud.core.db.Db;
import com.hengby.hengcrud.modular.sys.mapper.OperationLogMapper;
import com.hengby.hengcrud.modular.sys.model.OperationLog;
import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * 〈一句话功能简述〉<br> 
 * 〈日志操作认为创建工厂〉
 *
 * @author zhouheng
 * @create 2018/7/10
 * @since 1.0.0
 */
@Slf4j
public class LogTaskFactory {

    private static OperationLogMapper operationLogMapper =
            Db.getMapper(OperationLogMapper.class);

    public static TimerTask bussinessLog(final Integer userId, final String bussinessName,
                     final String clazzName, final String methodName, final String msg) {

        return new TimerTask(){
            @Override
            public void run() {
                OperationLog operationLog = LogFactory.createOperationLog(
                        LogType.BUSSINESS, userId, bussinessName,
                        clazzName, methodName, msg, LogSucceed.SUCCESS);

                try {
                    operationLogMapper.insert(operationLog);
                } catch (Exception e) {
                    log.error("创建业务日志异常!", e);
                }
            }
        };
    }

}